﻿using System.Collections.Generic;
namespace YuoTools
{
    public abstract class PoolsBase<T>
    {
        List<T> Items = new List<T>();
        List<T> Pools = new List<T>();
        public void Destroy(T item)
        {
            if (Items.Contains(item))
            {
                Items.Remove(item);
                Pools.Add(item);
            }
            else
            {
                $"要移除的物体 [{item}] 不属于该对象池".Log("#ff0000");
            }
        }
        public T ItemTemp;
        public T GetItem()
        {
            if (Pools.Count > 0)
            {
                ItemTemp = Pools[0];
                Pools.Remove(ItemTemp);
            }
            else
            {
                ItemTemp = CreatItem();
            }
            Items.Add(ItemTemp);
            ReSetItem(ItemTemp);
            return ItemTemp;
        }
        public abstract T CreatItem();
        public abstract void ReSetItem(T item);
    }
}